<style lang="less">
    @import "loanCommonTask.less";
    @import "./style/row-background.less";
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card>
                    <Row class="operation">
                        <Button @click="setHighest('yes')" type="primary">置顶</Button>
                        <Button @click="setHighest('no')" type="primary">取消置顶</Button>
                        <Button @click="setLock('yes')" type="primary" icon="md-lock">锁定</Button>
                        <Button @click="setLock('no')" type="primary" icon="md-unlock">解锁</Button>
                        <Button @click="changeOwnerList" type="primary">批量改派</Button>
                        <Button @click="setDiscard" type="primary">废弃</Button>
                        <Button @click="addTags" type="primary" icon="md-settings">打标签</Button>
                        <circleLoading v-if="operationLoading"/>
                    </Row>
                    <Row>
                        <Form  ref="searchForm" :model="searchForm" inline :label-width="120" class="search-form" @keydown.native.enter.prevent="handleSearch">
                            <Form-item label="合同号码" prop="contractNo">
                                <Input type="text" v-model="searchForm.contractNo" clearable placeholder="请输入合同号码"
                                       style="width: 160px"/>
                            </Form-item>
                            <Form-item label="客户姓名" prop="custName">
                                <Input type="text" v-model="searchForm.custName" clearable placeholder="请输入客户姓名"
                                       style="width: 160px"/>
                            </Form-item>
                            <Form-item label="申请编号" prop="applyNo">
                                <Input type="text" v-model="searchForm.applyNo" clearable placeholder="请输入申请编号"
                                       style="width: 160px"/>
                            </Form-item>
                            <span v-if="drop">
                                <Form-item label="经销商名称" prop="dealerName">
                                    <Input type="text" v-model="searchForm.dealerName" clearable placeholder="请输入经销商名称"
                                           style="width: 160px"/>
                                </Form-item>
                                <Form-item label="客户身份证号" prop="customerIdCard">
                                    <Input type="text" v-model="searchForm.customerIdCard" clearable placeholder="请输入客户身份证号"
                                           style="width: 160px"/>
                                </Form-item>
                                <Form-item label="案件状态" prop="applyStatus">
                                    <Select v-model="searchForm.applyStatus" style="width:160px" clearable placeholder="请选择案件状态">
                                        <Option v-for="item in dataDic.conApplyStatus" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="业务类型" prop="businessType">
                                    <Select v-model="searchForm.businessType" style="width:160px" clearable placeholder="请选择申请类型">
                                        <Option v-for="item in businessTypeList" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="车辆类型" prop="carType">
                                    <Select v-model="searchForm.carType" style="width:160px" clearable placeholder="请选择车辆类型">
                                        <Option v-for="item in dataDic.carType" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="车辆属性" prop="carNature">
                                    <Select v-model="searchForm.carNature" style="width:160px" clearable placeholder="请选择车辆属性">
                                        <Option v-for="item in  dataDic.carNature" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="运营方式" prop="operateWay">
                                    <Select v-model="searchForm.operateWay" style="width:160px" clearable placeholder="请选择运营方式">
                                        <Option v-for="item in dataDic.operateWay" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="挂靠方式" prop="affiliatedWay">
                                    <Select v-model="searchForm.affiliatedWay" style="width:160px" clearable placeholder="请选择挂靠方式">
                                        <Option v-for="item in dataDic.affiliatedWay" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="放款模式" prop="lendingMode">
                                    <Select v-model="searchForm.lendingMode" style="width:160px" clearable placeholder="请选择放款模式">
                                        <Option v-for="item in dataDic.lendingMode" :value="item.value" :label="item.title" :key="item.value">{{ item.title }}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="放款申请时间"  prop="passFirstDate">
                                    <DatePicker v-model="selectDate" type="daterange" format="yyyy-MM-dd" clearable
                                                @on-change="selectDateRange" placeholder="选择起始时间"
                                                style="width: 160px"></DatePicker>
                                </Form-item>
                                <Form-item label="车辆品牌" prop="brandName">
                                    <Select v-model="searchForm.brandCode" filterable clearable placeholder="请选择车辆品牌" style="width:160px;">
                                        <Option v-for="item in this.brandNameList" :label="item.brandName" :value="item.brandCode" :key="item.value">{{item.brandName}}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="案件标记"  prop="caseLabel">
                                    <Select v-model="searchForm.caseLabel" filterable clearable placeholder="请选择案件标记" style="width:160px;">
                                        <Option v-for="item in this.labelList" :label="item.labelName" :value="item.labelId" :key="item.value">{{item.labelName}}</Option>
                                    </Select>
                                </Form-item>
                                <Form-item label="当前处理人"  prop="approveStaffName">
                                    <Input type="text" v-model="searchForm.approveStaffName" clearable placeholder="当前处理人" style="width: 160px"/>
                                </Form-item>
                                <Form-item label="优先级"  prop="priority">
                                    <Select v-model="searchForm.priority" filterable clearable placeholder="请选择优先级" style="width:160px;">
                                        <Option v-for="item in dataDic.priority" :label="item.title" :value="item.value" :key="item.value">{{item.title}}</Option>
                                    </Select>
                                </Form-item>
                            </span>
                            <Form-item style="margin-left: -35px;" v-if="dropDownContent=='展开'">
                                <Button @click="handleSearch" type="primary" icon="ios-search">查询</Button>
                                <Button @click="handleReset" type="primary" icon="ios-trash">重置</Button>
                                <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                    <Icon :type="dropDownIcon"></Icon>
                                </a>
                            </Form-item>
                            <Form-item style="margin-left: -65px;width:100%;text-align: center;" v-if="dropDownContent=='收起'">
                                <Button @click="handleSearch" type="primary" icon="ios-search">查询</Button>
                                <Button @click="handleReset" type="primary" icon="ios-trash">重置</Button>
                                <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                    <Icon :type="dropDownIcon"></Icon>
                                </a>
                            </Form-item>
                        </Form>
                    </Row>
                    <Row>
                        <Alert show-icon>
                            已选择 <span class="select-count">{{selectCount}}</span> 项
                            <a class="select-clear" @click="clearSelectAll">清空</a>
                        </Alert>
                    </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" :row-class-name="rowClassName"
                               @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table">
                            <template slot-scope="{ row, index }" slot="action">
                                <Button type="primary" size="small" @click="changeOwner(row)">改派</Button>
                                <Button style="margin-right:5px"    type="primary" size="small" @click="showLogs(row)">查看日志
                                </Button>
                                <Button type="primary" size="small" @click="disCardLoan(row)">废弃</Button>
                            </template>
                            <template slot-scope="{ row, index }" slot="businessType">
                                <span>{{setBusinessTypeTitle(row.businessType)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="carType">
                                <span>{{setCarTypeTitle(row.carType)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="isLock">
                                <span>{{setIsLockTitle(row.isLock)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="applyStatus">
                                <span>{{setApplyStatusTitle(row.applyStatus)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="lendingMode">
                                <span>{{setLendingModeTitle(row.lendingMode)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="tags">
                                <Tag v-for="item in row.labelList" :color="item.labelColor" >{{item.labelName}}</Tag>
                            </template>
                            <template slot-scope="{ row, index }" slot="topType">
                                <span>{{setIsLockTitle(row.isTop)}}</span>                            </template>
                            <template slot-scope="{ row, index }" slot="contractNo">
                                <DynamicLink component="projects/afs-core-business/pages/case/approve/loan-audit/loanAuditView"
                                             :is-full="true"
                                             :params="{busiNo:row.contractNo,taskId:row.id,applyNo:row.applyNo,contractNo:row.contractNo,applyStatus:row.applyStatus,lendingFirstDate:row.lendingFirstDate,isLock:row.isLock,reviewSign:row.reviewSign,auditMode:false}"
                                             :name="row.contractNo+row.tags"
                                             page-title="案件详情">
                                </DynamicLink>
                                <bubble :data="row.remarks" v-if="row.isShowBubble" style="    margin-top: -50px;margin-left: 80px;"></bubble>
                            </template>
                        </Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize"
                              @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]"
                              size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                </Card>
            </Col>
        </Row>
        <Modal v-model="makeLoanLabelVisible" ref="makeLoanlabelOptionModel" :label-width="80" :title="modalTitle" :closable="false" :mask-closable='false' :width="600" :styles="{top: '180px'}">
            <div slot="footer">
                <Button type="text" @click="cancelLabel">取消</Button>
                <Button type="primary" @click="submitLabel">提交</Button>
            </div>
            <Row>
                <Form ref="makeLoanLabelOptionForm" :model="makeLoanLabelOptionForm" inline :label-width="80" class="search-form" :rules="formValidate">
                    <Form-item  label="标签名称" prop="labelName">
                        <Input type="textarea" v-model="makeLoanLabelOptionForm.labelName" clearable placeholder="请输入标签" style="width: 450px;height: 50px;" />
                    </Form-item>
                </Form>
            </Row>
        </Modal>
        <Modal v-model="markDiscardVisible" ref="makeLoanDiscardOptionModel" :label-width="80" :title="modalTitle" :closable="false" :mask-closable='false' :width="600" :styles="{top: '180px'}">
            <div slot="footer">
                <Button type="text" @click="cancelDiscard">取消</Button>
                <Button type="primary" @click="aloneSubmitDiscard" v-if="aloneDiscardVisble">提交</Button>
                <Button type="primary" @click="submitDiscard" v-if="!aloneDiscardVisble">提交</Button>
            </div>
            <Row>
                <Form ref="makeLoanDiscardOptionForm" :model="makeLoanDiscardOptionForm" inline :label-width="80" class="search-form" :rules="formValidate">
                    <Form-item  label="废弃原因" prop="labelName">
                        <Input type="textarea" v-model="makeLoanDiscardOptionForm.discardResult" clearable placeholder="请输入废弃原因" style="width: 450px;height: 50px;" />
                    </Form-item>
                </Form>
            </Row>
        </Modal>
        <loan-approve-record v-model="recordVisible" ref="approveRecord" :contractNo="contractNoParam" :applyNo="applyNoParam" />
        <modal v-model="lockFormVisible"
               ref="lockOptionModel"
               :label-width="80"
               :title="modalTitle"
               :closable="false"
               :mask-closable='false'
               :width="600"
               :styles="{top: '180px'}">
            <div slot="footer">
                <Button type="text" @click="cancelLock">取消</Button>
                <Button v-if="lockOptionStatus=='yes'" type="primary" @click="submitLock">提交</Button>
                <Button v-if="lockOptionStatus=='no'" type="primary" @click="setUnLock('no')">提交</Button>
            </div>
            <Row>
                <Form ref="lockOptionForm" :model="lockOptionForm" inline :label-width="80" class="search-form" :rules="formValidate">
                    <Form-item v-if="lockOptionStatus=='yes'" label="锁定原因" prop="processRemark">
                        <Input type="textarea" v-model="lockOptionForm.processRemark" clearable placeholder="请输入锁定原因" style="width: 450px;height: 50px;" />
                    </Form-item>
                    <Form-item v-if="lockOptionStatus=='no'" label="解锁原因" prop="processRemark">
                        <Input type="textarea" v-model="lockOptionForm.processRemark" clearable placeholder="解锁原因" style="width: 450px;height: 50px;" />
                    </Form-item>
                </Form>
            </Row>
        </modal>
        <task-handler :value="appointVisible" @cancel="cancelAppoint" :task-ori-user-name="taskOriOwner"    :apply-no="appointApplyNo"
                      :stage-id="stageId" :taskNodeIdProp="nodeId" @afterSubmit="afterAppoint"
        />
        <loan-task-handler-list :value="changeOwnerListVisible" :changeOwnerParamList="changeOwnerParamList" @cancel="cancelAppoint"  @afterSubmit="afterAppoint"
        />
    </div>
</template>
<script>
    //公共任务组装查询
    import {
        getLoanCommonTaskList
    } from "@/projects/afs-core-business/api/afs-case/loan-approve/loanCommonTask";
    //数据字典
    import {
        getByTypes
    } from "_p/basic/api/admin/datadic";

    import circleLoading from "_c/circle-loading/circle-loading.vue";
    //引打标签vue
    //import makelabel from "../make-label/makeLoanLabel";
    //根据申请编号获取一打标签
    import {
        queryLabelByApplyNo
    } from "@/projects/afs-core-business/api/afs-case/make-label/makeLoanLabel";
    //获取所有标签信息
    import {
        getAllLabelList
    } from "@/projects/afs-core-business/api/afs-case/manual-label/manualLabel";
    import bubble from './style/bubble.vue';
    import loanApproveRecord from '../loan-approve-record/loan-approve-record'
    //置顶、解锁、标签
    import {
        modifyLock,
        modifyLabel,
        modifyStick,
        loanDiscard,
        getLabelList,
        getBrandNameList
    } from '@/projects/afs-core-business/api/afs-case/loan-approve/loanApproveTask'
    import TaskHandler from "./loanTaskHandler";
    import loanTaskHandlerList from "./loanTaskHandlerList"
    export default {
        name: "approve-task",
        components: {
            loanTaskHandlerList,
            loanApproveRecord,
            circleLoading,
            bubble,
            TaskHandler
        },
        data() {
            return {
                recordVisible:false,
                aloneDiscardVisble: false,
                makeLabelVisible:false,
                markDiscardVisible:false,
                changeOwnerListVisible:false,
                appointVisible:false,
                modalTitle:"标签信息",
                disCardNo:'',
                loading: true,
                labelList: [],
                operationLoading: false,
                applyNoParam:'',
                contractNoParam: '',
                applyno:"",
                stageId: '',
                nodeId: '',
                taskOriOwner:'',
                operationType:null,
                locationData: [],
                selectDate:null,
                appointApplyNo:null,
                searchForm: {
                    priority:"",
                    applyNo: "",
                    contractNo:"",
                    applyStatus:"",
                    carType:"",
                    carNature:"",
                    customerIdCard:"",
                    passFirstDate:"",
                    operateWay:"",
                    affiliatedWay:"",
                    lendingMode:"",
                    brandName:"",
                    submitDateStart:null ,
                    submitDateEnd:null,
                    disposeStaff:"",
                    isTop:"",
                    custName:"",
                    bondManName:"",
                    downPayScaleStart:"",
                    downPayScaleEnd:"",
                    businessStatusIn:"",
                    taskNodeName:"",
                    isLock:"",
                    carName:"",
                    dealerName:"",
                    dealerNo:"",
                    loanAmountStart:"",
                    loanAmountEnd:"",
                    scoreShow:"",
                    tag:"",
                    processType:"",
                    businessType:""
                },
                selectList: [],
                selectCount: 0,
                tags: '',
                modalType: 0,
                errorPass: "",
                processTypeList:[],
                changeOwnerParamList:[],
                isOpen:[],
                businessTypeList:[],
                applyStatusList:[],
                carType:[],
                carNature:[],
                operateWay:[],
                priority:[],
                channelType: [],
                affiliatedWay:[],
                lendingModeList:[],
                brandNameList:[],
                isLock:[],
                isTop:[],
                businessStatusIn:[],
                makeLoanLabelVisible: false,
                makeLoanLabelOptionForm: {
                    labelName: ''
                },
                makeLoanDiscardOptionForm: {
                    discardResult:''
                },
                lockFormVisible:false,
                lockOptionStatus : '',
                lockOptionForm: {
                    processRemark: ''
                },
                topOptionStatus: '',
                dropDownContent: '展开',
                dropDownIcon: 'ios-arrow-down',
                drop: false,
                dicKeys: [
                    'businessType',
                    'conApplyStatus',
                    'carType',
                    'carNature',
                    'operateWay',
                    'affiliatedWay',
                    'lendingMode',
                    'channelType',
                    'priority'
                ],
                secondsAgo: 0,
                interval: null,
                formValidate: {
                    processRemark: [{required: true, message: "备注不能为空", trigger: "blur"}]
                },
                columns: [
                    {
                        type: "selection",
                        minWidth: 60,
                        maxWidth:60,
                        align: "center",
                        fixed: "left",
                        className: 'select-table-info-column'
                    },
                    {
                        title: "操作",
                        key: "action",
                        minWidth: 230,
                        align: "center",
                        fixed: "left",
                        slot: "action",
                        className: 'select-table-info-column'
                    },
                    {
                        title: "合同号码",
                        key: "contractNo",
                        minWidth: 165,
                        align: "center",
                        fixed: "left",
                        slot: "contractNo",
                        sortable: true,
                    },
                    {
                        title: "客户姓名",
                        key: "custName",
                        minWidth: 165,
                        sortable: true,
                        fixed: "left",
                    },
                    {
                        title: "案件状态",
                        key: "applyStatus",
                        sortable: true,
                        minWidth: 120,
                        slot:"applyStatus"
                    },
                    {
                        title: "合作商名称",
                        key: "dealerName",
                        sortable: true,
                        minWidth: 165
                    },
                    {
                        title: "案件标记",
                        key: "tags",
                        minWidth: 280,
                        sortable: true,
                        slot:"tags"
                    },
                    {
                        title: "申请编号",
                        key: "applyNo",
                        minWidth: 165,
                        sortable: true,
                    },
                    {
                        title: "车辆品牌",
                        key: "brandName",
                        minWidth: 280,
                        sortable: true,
                    },
                    {
                        title: "业务类型",
                        key: "businessType",
                        type:'singleSelect',
                        sortable: true,
                        minWidth: 165,
                        slot:"businessType"
                    },
                    {
                        title: "放款模式",
                        key: "lendingMode",
                        type:'singleSelect',
                        sortable: true,
                        minWidth: 110,
                        slot:"lendingMode"
                    },
                    {
                        title: "流程节点",
                        key: "taskNodeName",
                        minWidth: 110,
                        sortable: true,
                    },
                    {
                        title: "当前审核员",
                        key: "approveStaffName",
                        align: "center",
                        sortable: true,
                        minWidth: 165,
                        className: 'demo-table-info-cell-staff',
                    },
                    /*{
                        title: "审核员账号",
                        key: "approveStaff",
                        align: "center",
                        sortable: true,
                        minWidth: 120,
                    },*//**暂时取消，配置新流程可以自动获取登录人账号*/
                    {
                        title: "优先级",
                        key: "priority",
                        sortable: true,
                        minWidth: 110
                    },
                    {
                        title: "放款申请时间",
                        key: "lendingFirstDate",
                        sortable: true,
                        minWidth: 160
                    },
                    {
                        title: "欺诈风险",
                        key: "fraudInfo",
                        type:'singleSelect',
                        sortable: true,
                        minWidth: 110,
                    },
                    {
                        title: "是否置顶",
                        key: "isTop",
                        minWidth: 110,
                        slot:"topType",
                        sortable: true,
                    },
                ],
                data: [],
                total: 0
            };
        },
        methods: {
            init() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getTaskList();
                this.initDataDic();
                this.queryLabelData();
                this.getLabelList()
                this.getBrandNameList()

            },
            initDataDic() {
                let self = this
                getByTypes(this.dicKeys).then(res => {
                    if (res.code === '0000' && res.data) {
                        self.dataDic = res.data
                        this.businessTypeList.push(...res.data.businessType)
                        this.applyStatusList.push(...res.data.conApplyStatus)
                        this.carType.push(...res.data.carType)
                        this.carNature.push(...res.data.carNature)
                        this.operateWay.push(...res.data.operateWay)
                        this.affiliatedWay.push(...res.data.affiliatedWay)
                        this.lendingModeList.push(...res.data.lendingMode)
                        this.priority.push(...res.data.priority);
                        this.channelType.push(...res.data.channelType)
                    }
                })
            },
            created(){
                this.afs.afsOn(this,"flushData",()=>{
                    this.getTaskList();
                })
            },
            beforeDestroy(){
                if (this.interval) {
                    clearInterval(this.interval);
                }
                this.afs.afsOff(this,"flushData");
            },
            getLabelList(){
                getLabelList().then(res=>{
                    this.labelList = res.data;
                    console.log(res.data)
                })
            },
            getBrandNameList(){
                getBrandNameList().then(res=>{
                    this.brandNameList = res.data;
                })
            },
            // businessStatusIn_change: function (e) {
            //     if (e.businessStatusIn==='adviceConditional') {//建议附条件核准-绿色
            //         return 'table-info-row-green'
            //     }else if(e.businessStatusIn==='adviceApproved'){//建议核准案件-蓝色
            //         return 'table-info-row-blue'
            //     }else if(e.businessStatusIn==='adviceReject') {//建议核准案件-红色
            //         return 'table-info-row-red'
            //     }else if(e.businessStatusIn==='reviseReply') {//建议核准案件-黄色
            //         return 'table-info-row-yellow'
            //     }
            // },
            rowClassName (row, index) {
                if (row.isLock =="yes") {
                    return 'demo-table-lock-row';
                }
                if(row.isOverdue=="yes"){
                    return 'demo-table-overdue-row';
                }
                if(row.needReview=="yes"){
                    return 'demo-table-retrial-row';
                }

                return '';
            },
            queryLabelData() {
                this.load= true;
                this.searchForm.label='manual';
                this.searchForm.status='takeEffect';
                getAllLabelList(this.searchForm).then(res => {
                    this.load = false;
                    if (res.code === "0000") {
                        this.locationData= res.data.records;
                    }
                });
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = '展开'
                    this.dropDownIcon = 'ios-arrow-down'
                } else {
                    this.dropDownContent = '收起'
                    this.dropDownIcon = 'ios-arrow-up'
                }
                this.drop = !this.drop
            },
            handleSearch() {
                this.searchForm.pageNumber = 1;
                if (this.searchForm.pageSize == '' || this.searchForm.pageSize == null){
                    this.searchForm.pageSize = 10;
                }
                this.getTaskList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.brandCode =''
                this.searchForm.caseLabel =''
                this.searchForm.startDate = null;
                this.searchForm.endDate = null;

                // 重新加载数据
                this.getTaskList();
            },
            addTags() {
                if (this.hasSelectedLabel()) {
                    this.modalTitle = '案件打标签'
                    this.makeLoanLabelVisible = true
                }
            },
            //置顶
            setHighest(status) {
                if (this.hasSelected()) {
                    if(this.existsCurrentStatus("2",status)){
                        this.$Message.warning("已选择数据存在" +
                            (status == "yes" ? "已置顶" : "非置顶") +
                            "数据，请去除勾选后再操作");
                    } else {
                        this.topOptionStatus=status
                        this.operationLoading = true
                        this.loading = true
                        let data = []
                        this.selectList.forEach(function(e) {
                            data += e.contractNo + ','
                        })
                        modifyStick(
                            data,
                            this.topOptionStatus
                        ).then(res => {
                            if (res.code == '0000') {
                                this.$Message.success('操作成功')
                                this.getTaskList()
                            }
                        })
                        this.loading = false
                        this.operationLoading = false
                    }
                }
            },
            setUnHighest(status){},
            hasSelected() {
                if (this.selectCount == 0) {
                    this.$Message.warning("需先勾选数据行!");
                    return false;
                } else {
                    return true;
                }
            },
            hasSelectedLabel() {
                if (this.selectCount == 0) {
                    this.$Message.warning('需先勾选数据行!')
                    return false
                } else if(this.selectCount != 1) {
                    this.$Message.warning('打标签只能勾选一行数据行!')
                    return false
                } else {
                    return true
                }
            },
            existsCurrentFlowNode() {
                let currentStatusNum = 0;
                this.selectList.forEach(v => {
                    if(v.flowNode!='review'&& v.flowNode!='primary'){
                        currentStatusNum++;                    }
                });
                return currentStatusNum > 0;
            },
            existsCurrentStatus(type, status) {
                let currentStatusNum = 0;
                this.selectList.forEach(record => {
                    if (type == "1") {
                        console.log(record.isLock)
                        console.log(status)
                        if (record.isLock == status) {
                            currentStatusNum++;
                        }
                    } else if (type == "2") {
                        if (record.isTop == status) {
                            currentStatusNum++;
                        }
                    }
                });
                return currentStatusNum > 0;
            },
            //废弃放款申请
            setDiscard(){
                if (this.hasSelected()) {
                    this.modalTitle = '废弃放款申请'
                    this.aloneDiscardVisble = false
                    this.markDiscardVisible = true
                }
            },
            //批量改派
            changeOwnerList(){
                if (this.hasSelected()) {
                    if(this.existsCurrentFlowNode()){
                        this.$Message.warning("已选择数据存在不是 （初审/复审） 节点的案件，请去除勾选后再操作！")
                    }else {
                        this.changeOwnerParamList = this.selectList;
                        console.log(this.selectList,"this.selectList")
                        this.changeOwnerListVisible = true;
                    }
                }
            },
            //加锁
            setLock(status) {
                if (this.hasSelected()) {
                    if(this.existsCurrentStatus("1",status)){
                        this.$Message.warning(
                            "已选择数据存在" +
                            (status == "yes" ? "已锁定" : "非锁定") +
                            "数据，请去除勾选后再操作");
                    }else {
                        if (status == "yes") {
                            this.modalTitle = "锁定操作备注";
                            this.lockFormVisible = true;
                        } else {
                            this.modalTitle = "解锁操作备注";
                            this.lockFormVisible = true;
                        }
                        this.lockOptionStatus = status;
                    }
                }
            },
            //解锁
            setUnLock(status) {
                if (this.hasSelected()) {
                    if (this.existsCurrentStatus('1', status)) {
                        this.$Message.warning(
                            '已选择数据存在' +
                            (status == 'yes' ? '已锁定' : '非锁定') +
                            '数据，请去除勾选后再操作'
                        )
                    }else{
                        this.lockOptionStatus=status
                        let validResult = true
                        this.$refs.lockOptionForm.validate(valid => {
                            if (!valid) {
                                this.$Message.error('数据不合规，请检查数据项')
                                validResult = false
                            }
                        })
                        if (validResult) {
                            this.operationLoading = true
                            this.loading = true
                            let data = []
                            this.selectList.forEach(function(e) {
                                data += e.contractNo + ','
                            })
                            modifyLock(
                                data,
                                this.lockOptionForm.processRemark,
                                this.lockOptionStatus
                            ).then(res => {
                                if (res.code == '0000') {
                                    this.$Message.success('操作成功')
                                    this.getTaskList()
                                }
                            })
                            this.loading = false
                            this.cancelLock()
                            this.operationLoading = false
                        }
                    }
                }
            },
            //锁定备注提交
            submitLock() {
                let validResult = true;
                this.$refs.lockOptionForm.validate(valid =>{
                    if(!valid){
                        this.$Message.error("数据不合规，请检查数据项");
                        validResult = false;
                    }
                });
                if(validResult) {
                    this.operationLoading = true;
                    this.loading = true;
                    let data = [];
                    this.selectList.forEach(function (e) {
                        data += e.contractNo + ",";
                    });
                    modifyLock(
                        data,
                        this.lockOptionForm.processRemark,
                        this.lockOptionStatus
                    ).then(res => {
                        if (res.code == "0000") {
                            this.$Message.success("操作成功");
                            this.getTaskList();
                        }
                    });
                    this.loading = false;
                    this.cancelLock();
                    this.operationLoading = false;
                }
            },
            //标签提交
            submitLabel() {
                let validResult = true
                this.$refs.makeLoanLabelOptionForm.validate(valid => {
                    if (!valid) {
                        this.$Message.error('数据不合规，请检查数据项')
                        validResult = false
                    }
                })
                if (validResult) {
                    this.operationLoading = true
                    this.loading = true
                    let data = []
                    this.selectList.forEach(function(e) {
                        data += e.contractNo + ','
                    })
                    modifyLabel(
                        data,
                        this.makeLoanLabelOptionForm.labelName,
                    ).then(res => {
                        if (res.code == '0000') {
                            this.$Message.success('操作成功')
                            this.getTaskList()
                        }
                    })
                    this.loading = false
                    this.cancelLabel()
                    this.operationLoading = false
                }
            },
            //单个废弃提交
            aloneSubmitDiscard(){
                this.operationLoading = true
                this.loading = true
                loanDiscard(
                    this.disCardNo,
                    this.makeLoanDiscardOptionForm.discardResult,
                ).then(res => {
                    if (res.code == '0000') {
                        this.$Message.success('操作成功')
                        this.makeLoanDiscardOptionForm.discardResult = '',
                        this.aloneDiscardVisble = false
                        this.getTaskList()
                    }
                })
                this.loading = false
                this.cancelDiscard()
                this.operationLoading = false
            },
            //废弃提交
            submitDiscard(){
                let validResult = true
                this.$refs.makeLoanDiscardOptionForm.validate(valid => {
                    if (!valid) {
                        this.$Message.error('数据不合规，请检查数据项')
                        validResult = false
                    }
                })
                if (validResult) {
                    this.operationLoading = true
                    this.loading = true
                    let data = []
                    this.selectList.forEach(function(e) {
                        data += e.contractNo + ','
                    })
                    loanDiscard(
                        data,
                        this.makeLoanDiscardOptionForm.discardResult,
                    ).then(res => {
                        if (res.code == '0000') {
                            this.$Message.success('操作成功')
                            this.makeLoanDiscardOptionForm.discardResult = '',
                            this.getTaskList()
                        }
                    })
                    this.loading = false
                    this.cancelDiscard()
                    this.operationLoading = false
                }
            },
            cancelLabel() {
                this.makeLoanLabelVisible = false
                this.makeLoanLabelOptionForm.labelName = ''
            },
            cancelDiscard() {
                this.aloneDiscardVisble = true
                this.markDiscardVisible = false
                this.makeLoanDiscardOptionForm.discardResult = ''
            },
            cancelLock(){
                this.lockFormVisible = false;
                this.lockOptionForm.processRemark = "";
            },
            cancel(){
                this.makeLabelVisible = false;
                this.getTaskList();
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getTaskList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
                this.data.forEach(tableData=>{
                    tableData._checked = false;
                    console.log("333"+tableData.applyNo);
                    e.forEach( data => {
                        if(data.applyNo == tableData.applyNo){
                            tableData._checked = true;
                        }
                    })
                })
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getTaskList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getTaskList();
            },
            showLogs(v) {
                this.applyNoParam = v.applyNo
                this.contractNoParam = v.contractNo;
                this.recordVisible = true;
            },

            changeOwner(v) {
                // 改派
                if(v.flowNode=='review'||v.flowNode=='primary'){
                    this.appointApplyNo = v.applyNo;
                    this.stageId = v.stageId;
                    this.nodeId = v.taskId;
                    this.appointVisible = true;
                    this.taskOriOwner = v.approveStaff;
                }else {
                    this.$Message.warning("只有 （初审/复审） 节点的案件才可以改派！")
                }
            },
            disCardLoan(v){
                //废弃
                this.aloneDiscardVisble = true
                this.disCardNo = v.contractNo
                this.modalTitle = '废弃放款申请'
                this.markDiscardVisible = true

            },
            getTaskList() {
                this.loading = true;
                let tag=this.searchForm.tag;
                if(tag!==""){
                    this.searchForm.tag= this.searchForm.tag.join(',');
                }
                getLoanCommonTaskList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.data = res.data.records;
                        this.total = res.data.total;
                        this.searchForm.tag="";
                        this.data.forEach(i=>{
                            if(i.lendingMode=='03'){
                                i.tags="(签约后放款)";
                            }else{
                                i.tags="";
                            }
                            if(i.remarks!=undefined&&i.remarks.length>0){
                                i.isShowBubble=true
                            }else{
                                i.isShowBubble=false
                            }
                        })
                    }
                    if(this.total > 0) {
                        this.startAddSeconds();
                    }
                });
                this.selectCount=0;
            },
            initProcessType(){
                let params = {
                    type: "processType"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.processTypeList = res.data;
                    }
                });
            },
            setProcessTypeTitle(val){
                let dic = {}
                this.processTypeList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            initBusinessType(){
                let params = {
                    type: "businessType"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.businessTypeList = res.data;
                    }
                });
            },
            setBusinessTypeTitle(val){
                let dic = {}
                this.businessTypeList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            initApplyStatusType(){
                let params = {
                    type: "conApplyStatus"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.applyStatusList = res.data;
                    }
                });
            },
            setApplyStatusTitle(val){
                let dic = {}
                this.applyStatusList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },

            initLendingModeType(){
                let params = {
                    type: "lendingMode"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.lendingModeList = res.data;
                    }
                });
            },
            setLendingModeTitle(val){
                let dic = {}
                this.lendingModeList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },

            initCarType(){
                let params = {
                    type: "carType"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.carType = res.data;
                    }
                });
            },
            setCarTypeTitle(val){
                let dic = {}
                this.carType.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            initYesOrNoType(){
                let params = {
                    type: "isType"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.isOpen = res.data;
                        this.isLock = res.data;
                        this.isTop = res.data;
                    }
                });
            },
            setIsOpenTitle(val){
                let dic = {}
                this.isLock.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            setIsLockTitle(val){
                if(val =='yes'){
                    return '是'
                }else{
                    return '否'
                }
            },
            setIsTopTitle(val){
                let dic = {}
                this.isLock.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            setisHighlightTitle(val){
                let dic = {}
                this.isTop.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            initBusinessStatusInType(){
                let params = {
                    type: "businessStateIn"
                }
                getDictDataByType(params.type).then(res =>{
                    if (res.code === "0000"){
                        this.businessStatusIn = res.data;
                    }
                });
            },
            setBusinessStatusInTitle(val){
                let dic = {}
                this.businessStatusIn.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            startAddSeconds() {
                if (this.interval) {
                    clearInterval(this.interval);
                }
                this.secondsAgo = 0;
                let _this = this;
                this.interval = setInterval(() => {
                    _this.secondsAgo++;
                }, 1000);
            },
            formatTimeUnit(seconds) {
                let hour = parseInt((seconds / 3600).toString());
                let minute = parseInt(((seconds % 3600) / 60).toString());
                let second = (seconds % 3600) % 60;
                return (hour < 10 ? "0" + hour : hour) +
                    " : " + (minute < 10 ? "0" + minute : minute) +
                    " : " + (second < 10 ? "0" + second : second);
            },
            cancelAppoint(){
                this.appointVisible = false
                this.changeOwnerListVisible = false
            },
            afterAppoint(){
                this.getTaskList();
                this.appointVisible = false
            },
        },
        watch: {
            secondsAgo(newVal, oldVal) {
                this.data.forEach(data => {
                    if (!data.originalSeconds) {
                        data.originalSeconds = 0;
                    }
                    data.timming = this.formatTimeUnit(data.originalSeconds + newVal);
                });
            }
        },
        /*mounted() {
            this.init();
        },*/
        activated() {
            this.init()
        },
    };
</script>
